import java.util.*;
class Solution {
    public int canCompleteCircuit(int[] gas, int[] cost) {

        int n=gas.length;
        int win=0;
        for(int i=0;i<gas.length;i++){
            int j=i;
            win=0;
            for(;j<n;){
                win+=gas[j]-cost[j];
                if(win<0) break;
                j=(j+1)%n;
                if(j==i) return  i;
            }
        }
        return -1;
    }
    public int canCompleteCircuit1(int[] gas, int[] cost) {
        int n=gas.length;
        int[] arr=new int[n];
        for(int i=0;i<n;i++){
            arr[i]=gas[i]-cost[i];
        }
        int left=0;
        while(left<n){
            int i=left;
            int sum=0;
            for(;i<n;){
                sum+=arr[i];
                if(sum<0) break;
                i=(i+1)%n;
                if(i==left) return left;
            }
            if(left>i) left++;
            else left=i+1;
        }
        return -1;
    }
}
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
  public static   int[] dy={1,-1,0,0};
    public static  int[] dx={0,0,1,-1};
    public static  int count=0;
    public static List<Integer> findPeaks(int[] mountain) {
        List<Integer> ret=new ArrayList<>();
        for(Integer i=1;i<mountain.length-1;i++){
            if(mountain[i]>mountain[i-1]&&mountain[i+1]<mountain[i]){
                ret.add(i);
            }
        }
        return ret;
    }
    public static int integerReplacement(int n) {
        if (n == 1) {
            return 0;
        }
        int count = 0;
        while (n > 1) {

            if (n % 2 == 0) {
                count++;
                n /= 2;
            } else {
                count++;
                if (n % 4 == 3)
                    n++;
                else
                    n--;
            }

        }
        return count;
    }
    public static int maxEnvelopes(int[][] envelopes) {
        Arrays.sort(envelopes,(a,b)->{
            if(a[0]!=b[0]){
                return  a[0]-b[0];
            }
            return b[1]-a[1];
        });
        ArrayList<Integer> ret=new ArrayList<>();
        ret.add(envelopes[0][1]);
        for(int i=1;i<envelopes.length;i++){
            int b=envelopes[i][1];
            if(b>ret.get(ret.size()-1)){
                ret.add(b);

            }else{
                int left=0;int rigth=ret.size()-1;
                while(left>rigth){
                    int mid=(left+rigth)/2;
                    if(ret.get(mid)>=b) rigth=mid;
                    else left=mid+1;
                }
                ret.set(left,b);
            }
        }
        return ret.size();
    }
    public static int lengthOfLongestSubstring(String s) {
        int len=0;
        for(int i=0;i<s.length();i++){
            int[] arr=new int[128];
            for(int j=i;j<s.length();j++){

                char ch=s.charAt(j);
                arr[ch]++;
                if(arr[ch]==2) len=Math.max(len,j-i);
            }
        }
        return len;
    }
    public  static  int findMinArrowShots(int[][] points) {

        Arrays.sort(points, new Comparator<int[]>() {
            public int compare(int[] point1, int[] point2) {
                if (point1[1] > point2[1]) {
                    return 1;
                } else if (point1[1] < point2[1]) {
                    return -1;
                } else {
                    return 0;
                }
            }
        });


        int count=1;
        long left=points[0][0],rigth=points[0][1];

        for(int i=1;i<points.length;i++){
            long l=points[i][0],r=points[i][1];
            if(rigth>=l){
                rigth=Math.min(rigth,r);

            }else{
                count++;
                rigth=r;
                left=l;
            }
        }
        return count;

    }
    public static void main(String[] args) {
    int[][] arr={{-2147483646,-2147483645},{2147483646,2147483647}};
        System.out.println(findMinArrowShots(arr));
//        int[] mountain={1,4,3,8,5};
//        List<Integer> list=findPeaks(mountain);
//        System.out.println(list);
//        int  n=56478;
//        char[] ret= Integer.valueOf(n).toString().toCharArray();
//        int left=0;
//        while(left+1<ret.length&&ret[left+1]>=ret[left]) left++;
//        while(left+1>=0&&ret[left-1]==ret[left]) left--;
//        ret[left]--;
//        for(int i=left+1;i<ret.length;i++){
//            ret[i]='9';
//        }
//        int aa= Integer.parseInt(new String(ret));
//        String ret="34";
//        char[] aee=ret.toCharArray();
//        int a=Integer.parseInt(ret);
//        System.out.println(a);
//        int[] gas={2,3,4};
//        int[] cost={3,4,3};
//        Solution solution=new Solution();
//        System.out.println(solution.canCompleteCircuit1(gas,cost));
    }
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        int n= in.nextInt();
        int m = in.nextInt();
        int[][] arr=new int[n][m];
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                arr[i][j]=in.nextInt();
            }
        }
        int a=0;
        int max=0;
        boolean[][] visited=new boolean[n][m];
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                a=df(arr,i,j,visited)+1;
                max=Math.max(max,a);
            }
        }
        System.out.println(max);
    }
    public static int df(int[][] arr,int strat,int end,boolean[][] visited){

         int count=0;
        for(int i=0;i<4;i++){
            boolean[][] ret=visited;
            int x=strat+dx[i];
            int y=end+dy[i];
            if(x>=0&&x<arr.length&&y>=0&&y<arr[0].length&&arr[strat][end]-arr[x][y]>=1&&!ret[x][y]){
                ret[x][y]=true;
                count+=1+df(arr,x,y,ret);
            }
        }
        return count;
    }
}